<?php

namespace Models;

use Phalcon\Db\RawValue;

class Act extends BaseModel
{

    public function initialize()
    {
        $this->hasMany("aid", "Models\ActUser", "id",array('alias' => 'ActUser'));
        $this->hasMany("aid","Models\WxAct","id",array('alias' => 'ActUser'));
        $this->belongsTo("token", "Models\Wx", "token", array('alias' => 'Wx'));
    }
    public function beforeValidationOnCreate()
    {
        if (!isset($this->aid) || !$this->aid) {
            $this->aid = new RawValue('default');
        } if (!isset($this->aid) || !$this->aid) {
        $this->aid = new RawValue('default');
    }
        if (!isset($this->name) || !$this->name) {
            $this->name = new RawValue('default');
        }
        if (!isset($this->place) || !$this->place) {
            $this->place = new RawValue('default');
        }
        if (!isset($this->detail) || !$this->detail) {
            $this->detail = new RawValue('default');
        }
        if (!isset($this->count) || !$this->detail) {
            $this->count = new RawValue('default');
        }
    }

    public function beforeValidationOnUpdate()
    {
        if (!isset($this->aid) || !$this->aid) {
            $this->aid = new RawValue('default');
        }
        if (!isset($this->name) || !$this->name) {
            $this->name = new RawValue('default');
        }
        if (!isset($this->place) || !$this->place) {
            $this->place = new RawValue('default');
        }
        if (!isset($this->detail) || !$this->detail) {
            $this->detail = new RawValue('default');
        }
        if (!isset($this->count) || !$this->detail) {
            $this->count = new RawValue('default');
        }
    }

    public function notSave()
    {
        //Obtain the flash service from the DI container
        $flash = $this->getDI()->getFlash();

        //Show validation messages
        foreach ($this->getMessages() as $message) {
            $flash->error($message);
        }
    }

}